package cn.edu.neusoft.neufooddemo.fragment;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import cn.edu.neusoft.neufooddemo.R;
import cn.edu.neusoft.neufooddemo.adapter.ShopAdapter;
import cn.edu.neusoft.neufooddemo.bean.Shop;
import cn.edu.neusoft.neufooddemo.listener.RetrofitListener;
import cn.edu.neusoft.neufooddemo.model.ShopModel;

public class HomeFragment extends BaseFragment implements RetrofitListener<List<Shop>>{
    private RecyclerView recyclerView;
    private ShopAdapter adapter;

    @Override
    public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) {
        setLayout_file(R.layout.tab01);
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    void initViews() {
        recyclerView = (RecyclerView) view.findViewById(R.id.rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    }

     void initData() {
        ShopModel shopModel = new ShopModel();
        shopModel.getAllShops(this);
    }

    @Override
    public void onSuccess(List<Shop> shops, int flag) {
        adapter = new ShopAdapter(getActivity(), shops, R.layout.cardview);
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void onFail() {
        showToast("网络连接失败");
    }
    void initEvents()
    {
    }
}
